package org.nokatag.Connection;

import java.sql.Connection;

import org.hibernate.Session;
import org.nokatag.system.BugInfoWrint;
import org.nokatag.system.HibernateUtil;
import org.nokatag.system.ServletNokaContext;

/**
 * hibernate连接
 * @author rebin
 *
 */
public class HibernateConnection implements DBConnectionInterface{

	/**
	 * 获取连接
	 */
	public Connection getConnection() {
		Session hsession=HibernateUtil.currentNewSession();//获取hibernate session
		ServletNokaContext.setHibernateSession(hsession);
		return hsession.connection();//获取connection
	}

	/**
	 * 关闭连接
	 */
	public void closeConnection(Connection con) {
		try{
			if(null!=con){
				try{con.close();}catch(Exception se){BugInfoWrint.Print(se);}
				HibernateUtil.closeSession(ServletNokaContext.getHibernateSession());//关闭当关session
			}
		}catch(Exception se){
			
		}
	}

}
